package com.itheima.d3_resource;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 目标：掌握释放资源的方式：try-with-resource
 */
public class Test2 {
        public static void main(String[] args) throws Exception {

            // 需求：复制照片。

            File src = new File("day09file-io-app/image01/R-C.jpg");

            File file = new File("day09file-io-app/image02/R-C.jpg");

            copyFile(src,file);
        }
        public static void copyFile(File src,File file) throws IOException {
            try ( FileInputStream fis = new FileInputStream(src);
                  FileOutputStream fos = new FileOutputStream(file))
                {
                byte[] buf = new byte[1024];
                int len;
                while ((len= fis.read(buf))!=-1){
                    fos.write(buf,0,len);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }



